package parser

import (
	"bytes"
	"luiz/crawler/engine"
	"luiz/crawler_distributed/config"
	"regexp"
)

const cityListRe = `<a href="//([^"]+)" class="Z_city_option ani">([^<]+)</a>`

func ParseCityList(contents []byte, _ string) engine.ParseResult {
	compile := regexp.MustCompile(cityListRe)
	findString := compile.FindAllStringSubmatch(string(contents), -1)
	result := engine.ParseResult{}
	for _, match := range findString {
		var bt bytes.Buffer
		bt.WriteString("http://")
		bt.WriteString(match[1])
		//ParserFunc: ParseHezuList
		result.Request = append(result.Request, engine.Request{Url: bt.String(), Parser: engine.NewFuncParser(ParseHezuList, config.ParseHezuList)})
		//fmt.Printf("%v %v\n", match[1], "城市："+match[2])
	}
	//fmt.Printf("Matches found: %d\n", len(findString))
	return result
}
